<?php
/**
 * Post advanced form for inclusion in the administration panels.
 *
 * @package WordPress
 * @subpackage Administration
 */
// don't load directly

//require_once('./admin.php');
//require( ABSPATH . WPINC . '/class-wp-editor.php' );
global $wpdb;

if (isset($_REQUEST['save']) && $_REQUEST['save'] == 'Update') {
    $dataslideshow['id'] = isset($_REQUEST['id']) ? $_REQUEST['id'] : "0";
    $dataslideshow['text'] = isset($_REQUEST['text']) ? $_REQUEST['text'] : "";
    $dataslideshow['slideshow'] = isset($_REQUEST['image']) ? $_REQUEST['image'] : "";
    $dataslideshow['title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : "";

    $dataslideshow = stripslashes_deep($dataslideshow);


    $wpdb->update('wp_slideshow', $dataslideshow, array('ID' => '1'));

    if (!$wpdb->show_errors()) {
        $message = " Banner updated ";
    } else {
        $notice = $wpdb->show_errors();
    }
}

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
$posts = $wpdb->get_results("SELECT * FROM wp_slideshow WHERE ID = 1", 'OBJECT');
$post = $posts[0];
require_once('./admin-header.php');
?>

<div class="wrap">
    <?php screen_icon(); ?>
    <h2>Banner Edit</h2>
    <?php if ($notice) : ?>
        <div id="notice" class="error"><p><?php echo $notice ?></p></div>
    <?php endif; ?>
    <?php if ($message) : ?>
        <div id="message" class="updated"><p><?php echo $message; ?></p></div>
    <?php endif; ?>
    <form name="post" action="#" method="post" id="post"<?php do_action('post_edit_form_tag'); ?>>
        <?php wp_nonce_field($nonce_action); ?>
        <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
        <input type="hidden" id="hiddenaction" name="action" value="edit" />
        <input type="hidden" id="hiddenaction" name="id" value="<?php echo $post->id ?>" />
        <div id="poststuff">

            <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
                <div id="post-body-content">

                    <div id="titlediv">
                        <div id="titlewrap">
                            <label class="hide-if-no-js" style="visibility:hidden" id="title-prompt-text" for="title"><?php echo apply_filters('enter_title_here', __('Enter title here'), $post); ?></label>
                            <input type="text" name="title" size="30" tabindex="1" value="<?php echo esc_attr(htmlspecialchars($post->title)); ?>" id="title" autocomplete="off" />
                        </div>
                        <div class="inside">
                        </div>
                    </div>
                    <div id="postdivrich" class="postarea">
                        <label for="Text"><h3>Text</h3></label>
                        <?php wp_editor($post->text, 'text', array('dfw' => true, 'tabindex' => 1)); ?>
                        <br /><br />
                        <label for="Image"><h3>Images</h3></label>
                        <?php wp_editor($post->slideshow, 'image'); ?>
                        <table id="post-status-info" cellspacing="0"><tbody><tr>
                                    <td id="wp-word-count"><?php printf(__('Word count: %s'), '<span class="word-count">0</span>'); ?></td>
                                    <td class="autosave-info">
                                        <span class="autosave-message">&nbsp;</span>
                                        <?php
                                        if ('auto-draft' != $post->post_status) {
                                            echo '<span id="last-edit">';
                                            if ($last_id = get_post_meta($post_ID, '_edit_last', true)) {
                                                $last_user = get_userdata($last_id);
                                                printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html($last_user->display_name), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
                                            } else {
                                                printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
                                            }
                                            echo '</span>';
                                        }
                                        ?>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div><!-- /post-body-content -->
                <div id="postbox-container-1" class="postbox-container">
                    <div class="postbox" id="submitdiv">
                        <div title="Click to toggle" class="handlediv"><br></div><h3 class="hndle"><span>Publish</span></h3>
                        <div class="inside">
                            <div id="submitpost" class="submitbox">
                                <div id="major-publishing-actions">
                                    <div id="publishing-action">
                                        <img alt="" id="ajax-loading" class="ajax-loading" src="http://azaleasuites.net/wp-admin/images/wpspin_light.gif" style="visibility: hidden;">
                                        <input type="hidden" value="Update" id="original_publish" name="original_publish">
                                        <input type="submit" value="Update" id="publish" class="button-primary" name="save">
                                    </div>
                                    <div class="clear"></div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<?php if ((isset($post->post_title) && '' == $post->post_title) || (isset($_GET['message']) && 2 > $_GET['message'])) : ?>
    <script type="text/javascript">
        try{document.post.title.focus();}catch(e){}
    </script>
<?php endif; ?>
